package com.kk.xhr.model.assembler;

import com.kk.xhr.common.pojo.EmployeeFromEnum;
import com.kk.xhr.common.pojo.RecruitStatusEnum;
import com.kk.xhr.model.dto.RecruitDTO;
import com.kk.xhr.model.entity.Recruit;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

/**
 * 招聘数据转换工具类
 *
 * @author kkmystery
 * @version 1.0 2021/2/28 11:31
 * @since 1.0.0
 */
@Mapper(componentModel = "spring")
public interface RecruitStructKit {

    RecruitStructKit INSTANCE = Mappers.getMapper(RecruitStructKit.class);

    /**
     * dto -> entity
     *
     * @param dto dto
     * @return entity
     */
    Recruit toEntity(RecruitDTO dto);

    /**
     * entity -> dto
     *
     * @param entity entity
     * @return dto
     */
    RecruitDTO toDto(Recruit entity);

    /**
     * RecruitStatusEnum类型 byte -> enum
     *
     * @param status 状态
     * @return RecruitStatusEnum
     */
    default RecruitStatusEnum statusConvertor(Byte status) {
        if (null == status) {
            return null;
        }
        return RecruitStatusEnum.from(status);
    }

    /**
     * RecruitStatusEnum类型 enum -> byte
     *
     * @param status 状态
     * @return byte
     */
    default Byte statusConvertor(RecruitStatusEnum status) {
        if (null == status) {
            return null;
        }
        return status.getValue();
    }

    /**
     * EmployeeFromEnum类型 byte -> enum
     *
     * @param status 状态
     * @return EmployeeFromEnum
     */
    default EmployeeFromEnum formConvertor(Byte status) {
        if (null == status) {
            return null;
        }
        return EmployeeFromEnum.from(status);
    }

    /**
     * EmployeeFromEnum类型 enum -> byte
     *
     * @param status 状态
     * @return byte
     */
    default Byte formConvertor(EmployeeFromEnum status) {
        if (null == status) {
            return null;
        }
        return status.getValue();
    }
}
